package edu.chl.dat076.datesite.entities;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

/**
 *
 * @author Christoffer
 */
@Entity
public class Town implements Serializable {
	private static final long serialVersionUID = 1L;
	
	@Id
    @GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;
	@Column(nullable = false)
	private String name;

	@ManyToOne
	@JoinColumn(name="TOWN_FK")
	County county;
	
	
	
	public Town() {
	}

	public Town(String name) {
		this.name = name;
	}

	public Town(String name, County county) {
		this.name = name;
		this.county = county;
	}
	
	
	
	public Long getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public County getCounty() {
		return county;
	}
	
	

	public void setName(String name) {
		this.name = name;
	}

	public void setCounty(County county) {
		this.county = county;
	}
	
	

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		final Town other = (Town) obj;
		if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
			return false;
		}
		if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
			return false;
		}
		if (this.county != other.county && (this.county == null || !this.county.equals(other.county))) {
			return false;
		}
		return true;
	}
	
	
	
	@Override
	public int hashCode() {
		int hash = 0;
		hash += (id != null ? id.hashCode() : 0);
		return hash;
	}
	
	

	@Override
	public String toString() {
		return name;
	}
}